<?php
class MoniesController extends AppController {

	var $name = 'Monies';

    function beforeFilter () {
        parent::beforeFilter();
    }
    
	function index() {
		$this->Money->recursive = 0;
		$this->set('monies', $this->paginate());
	}

    function edit($id=0) {

		if ( isset($_POST['save']) ) {
			
			if ($this->Money->save($this->data['Money'])) {
				$this->Session->setFlash(__('Guardado correctamente', true));
				$this -> redirect(array('action'=>'index'));
				exit();                
			} else {
				$this->Session->setFlash(__('No se pudo guardar el formulario.', true));
			}  
			
		} 
            
        if ($id == 0) {
                $this->set('title_nav_bar','Crear una Moneda');
                // Nuevo Plan
                $T = $this->Money->_schema;
                foreach($T as $clave => $valor) { $this->data['Money'][$clave] = $valor['default']; }
                $this->data['Money']['id'] = 0;    
        } else {
                $this->set('title_nav_bar','Editar Moneda (id:'.$id.')');
				$this->Moneda->recursive = 1;
                $this->data= $this->Money->read(null, $id);
				
        }
        
        
    }

	function delete($id = null) {
		if (empty($this->data['Delete'])) {
			$this->Session->setFlash(__('Debe seleccionar una Moneda', true));
			$this->redirect(array('action'=>'index'));
		} else {
 
            foreach($this->data['Delete'] as $key=>$value) {
                if ($value==1) { 
                    $this->Money->delete($key,true); 
                }
            }
            $this->Session->setFlash(__('Moneda/s eliminada/s', true));
    		$this->redirect(array('action'=>'index'));

		} 
	}
}
?>